package com.burgeon.backend.Rest.User;

/**
 * 修改vip信息
 */

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.entity.User;
import com.burgeon.backend.entity.VipAttrib;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;

public class ModVipDataBos extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public ModVipDataBos(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public void getData(String id, User data) throws Exception {

        String url = "http://" + ip + "/servlets/binserv/Rest";
        String str = RESULT(Data(id, data), url);

        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");
        if (!"0".equals(code)) {
            throw new Exception(message);
        }
    }

    private MultiValueMap Data(String id, User data) {

        HashMap params = new HashMap();

        params.put("ID", id);
        params.put("partial_update", "true");

        params.put("table", "C_VIP");//表名

        if (data.getPhone()!=null)
        params.put("MOBIL", "'" + data.getPhone() + "'");
        if (data.getPassword()!=null)
        params.put("PASS_WORD", "'" + data.getPassword() + "'");
        if (data.getName()!=null)
        params.put("VIPNAME", "'" + data.getName() + "'");
        if (data.getType()!=null)
        params.put("'C_VIPTYPE_ID__NAME'", "'" + data.getType() + "'");
        if (data.getCustomer()!=null)
        params.put("'C_CUSTOMER_ID__NAME'", "'" + data.getCustomer() + "'");
        if (data.getStore()!=null)
        params.put("'C_STORE_ID__NAME'", "'" + data.getStore() + "'");
        if (data.getEmp()!=null)
        params.put("'HR_EMPLOYEE_ID1__NAME'", "'" + data.getEmp() + "'");
        if (data.getGender()!=null)
        params.put("SEX", "'" + data.getGender() + "'");
        if (data.getOpenid()!=null)
        params.put("OPENID", "'" + data.getOpenid() + "'");
        if (data.getRemarks()!=null)
        params.put("DESCRIPTION", "'" + data.getRemarks() + "'");
        if (data.getBirthday()!=null)
        params.put("BIRTHDAY","'"+data.getBirthday()+"'");

        return DATA("ObjectModify", params, account, password);
    }

    public static void main(String[] args) {
        ModVipDataBos g = new ModVipDataBos("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            User user = new User();
            user.setBirthday("19930918");
            g.getData("256984", user);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
